<template>
  <div class="history-item">
    <div class="history-item-total">
      <p>已出借总额：<span>{{ investTotal.toFixed(2) }}元</span></p>
      <p>已出借总人数：<span>{{ investPeoples }}人</span></p>      
    </div>
    <div class="history-item-investmentList">
      <div class="border border-1px"></div>
      <table>
        <tr class="border-all-1px">
          <th>出借用户</th>
          <th>出借金额</th>
          <th>出借时间</th>
        </tr>
        <tr v-for="(item, index) in orderInvestmentList" class="border-all-1px">
          <td><span :class="icon(index)"></span>{{ item.mLoginname }}</td>
          <td>{{ item.investMoney }}</td>
          <td>{{ item.createDate }}</td>          
        </tr>
      </table>
    </div>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        investmentList: []
      }
    },
    computed: {
      investPeoples () {
        return this.investmentList.length
      },
      investTotal () {
        let total = 0
        this.investmentList.forEach((item) => {
          total += item.investMoney
        })
        return total
      },
      orderInvestmentList () {
        return this.investmentList.reverse() // 按时间顺序
      }
    },
    methods: {
      icon (index) {
        if (index === 0 || index === 1 || index === 2) {
          return 'icon-rank'
        } else {
          return 'icon-rank'
        }
      }
    },
    created () {
      this.$http.get(`/api/borrow/borrowInfo/borrowInvestRecord?currentPage=1&numPerPage=999&borrowOrder=${this.$route.params.borrowOrder}`)
        .then((res) => {
          if (res.data.success) {
            this.investmentList = res.data.data.list
          }
        })
        .catch((err) => {
          console.log(err)
        })
    }
  }
</script>

<style lang='scss'>
  @import '../../common/scss/tool.scss';
  @import '../../common/scss/_variable.scss';

  .history-item {
    &-total {
      p {
        margin-bottom: 30px;
        font-size: 28px;
        color: $base-666;
        span {
          color: $base-ff6c00;
          font-weight: normal;
        }
      }
    }
    &-investmentList {
      .border {
        @include border-1px(#{$base-e5e5e5});
      }
      table {
        width: 100%;       
        tr:nth-child(1) {
          display: flex;
          width: 100%;
          height: 48px;
          line-height: 58px;
          background: $base-f8f8f8;
          padding: 0;
          justify-content: space-between;
          th {
            &:nth-child(1) {
              width: 184px;
              text-align: right;
            }
            &:nth-child(2) {
              flex: 1;
            }
            &:nth-child(3) {
              width: 230px;
            }
          }
        }
        tr {
          display: flex;
          justify-content: space-between;
          @include border-all-1px(#{$base-e5e5e5});          
          border-top: none;
          height: 60px;
          line-height: 70px;
          padding: 0 20px;
          &::after {
            border-radius: 0;
            border-top: none;
          }
          &:nth-child(n + 1) {
            span {
              color: $transparent;
              margin-right: 10px;
            }
          }
          &:nth-child(2) {
            span {
              color: #ffe400;
            }
          }
          &:nth-child(3) {
            span {
              color: #bcbde2;
            }
          }
          &:nth-child(4) {
            span {
              color: #ffac43;
            }
          }
        }
        th {
          font-size: 30px;
          color: $base-666;
        }
        td {
          text-align: center;
          font-size: 28px;
          color: $base-999;
          font-weight: normal;
          &:nth-child(2) {
            flex: 1;
          }
        }
      }
    }
  }
</style>
